<template>
	<view class="book-container">
		<view class="page-wrapper">
			<view v-for="(item, index) in pageList" :key="item.id" class="page"
				:class="{ 'page-idle': !item.reading, 'page-left': index == currentPage + 1, 'page-right': index == currentPage + 2, 'page-none': index < currentPage || index > currentPage + 2 }">
				<image :src="item.url" class="page-image" />
				<view class="page-text">
					<view class="page-title">{{ item.title }}</view>
					<view class="page-content">{{ item.content }}</view>
				</view>
			</view>
		</view>
		<view class="page-footer">第 {{ currentPage + 1 }} / {{ maxPage }} 页</view>
		<view class="button-wrapper">
			<view class="page-button" @click="handleChangePage('prev')"
				:style="{ opacity: currentPage === 0 ? '0.5' : '1' }">
				<uv-icon name="arrow-left" size="20" color="#333"></uv-icon>
			</view>
			<view class="voice-button">
				<uv-icon name="volume" size="28" color="#fff"></uv-icon>
			</view>
			<view class="page-button" @click="handleChangePage('next')"
				:style="{ opacity: currentPage === maxPage - 1 ? '0.5' : '1' }">
				<uv-icon name="arrow-right" size="20" color="#333"></uv-icon>
			</view>
		</view>
		<view :style="currentPage === maxPage - 1 ? 'opacity: 1' : 'opacity: 0'" class="end-button" @click="handleFinish">
			完成
		</view>
		<uv-loading-page :loading="false" loading-text="加载中..." font-size="24rpx"></uv-loading-page>
	</view>
</template>

<script>
export default {
	data() {
		return {
			pageList: [
				{
					id: 1,
					url: '../../static/FRAME.png',
					title: '第一章：初入江湖',
					content: '这是一个关于江湖的故事，讲述了一个年轻的侠客如何踏上江湖之路，历经磨难，最终成为一代宗师的故事。',
					reading: true,
				},
				{
					id: 2,
					url: '../../static/FRAME.png',
					title: '第二章：江湖风波',
					content: '年轻的侠客在江湖中结识了许多志同道合的朋友，一起经历了许多江湖风波，最终成为了江湖中的一股强大力量。',
					reading: false,
				},
				{
					id: 3,
					url: '../../static/FRAME.png',
					title: '第三章：江湖传奇',
					content: '年轻的侠客在江湖中结识了许多志同道合的朋友，一起经历了许多江湖风波，最终成为了江湖中的一股强大力量。',
					reading: false,
				},
				{
					id: 4,
					url: '../../static/FRAME.png',
					title: '第四章：江湖传奇',
					content: '年轻的侠客在江湖中结识了许多志同道合的朋友，一起经历了许多江湖风波，最终成为了江湖中的一股强大力量。',
					reading: false,
				}
			],
			currentPage: 0, // 当前页码
			maxPage: 4, // 最大页码

		}
	},
	methods: {
		handleChangePage(direction) {
			if (direction === 'prev') {
				if (this.currentPage > 0) {
					this.pageList[this.currentPage--].reading = false;
					setTimeout(() => {
						this.pageList[this.currentPage].reading = true;
					}, 300)
				}
			} else {
				if (this.currentPage < this.maxPage - 1) {
					this.pageList[this.currentPage++].reading = false;
					setTimeout(() => {
						this.pageList[this.currentPage].reading = true;
					}, 300)
				}
			}
		},
		handleFinish() {
			uni.redirectTo({
				url: '/pages/index/index'
			})
		}
	}
}
</script>

<style lang="scss">
.book-container {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;

	.page-wrapper {
		width: 100%;
		height: 800rpx;
		border-radius: 10px;
		padding: 20px;
		position: relative;

		.page {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin: 30rpx auto;
			margin-bottom: 20rpx;
			width: 550rpx;
			border-radius: 24rpx;
			overflow: hidden;
			box-shadow: 0 3rpx 12rpx #eee;
			position: absolute;
			top: 30rpx;
			left: 0;
			right: 0;
			transition: all 0.3s ease-in-out;
			z-index: 10;

			// 盖上纯灰色蒙版
			&::after {
				transition: all 0.8s ease;
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				background-color: transparent; // 纯灰色蒙版
			}

			&-idle {
				&::after {
					background-color: #f3f4f6; // 纯灰色蒙版
				}
			}

			&-left {
				z-index: 9;
				transform: rotate(10deg);
			}

			&-right {
				z-index: 8;
				transform: rotate(-10deg);
			}

			// 剩下的隐藏
			&-none {
				display: none;
			}


			.page-image {
				width: 100%;
				height: 250px;
			}

			.page-text {
				display: flex;
				flex-direction: column;
				height: 250rpx;
				gap: 20rpx;
				padding: 40rpx;
				background-color: #fff;

				.page-title {
					font-size: 36rpx;
					font-weight: bold;
					margin-bottom: 10rpx;
				}

				.page-content {
					font-size: 28rpx;
					text-align: justify;
					letter-spacing: 0.05em;
					line-height: 1.5em;
					color: #333;
				}
			}
		}
	}

	.page-footer {
		margin-top: 80rpx;
		text-align: center;
		font-size: 28rpx;
		color: #333;
	}

	.button-wrapper {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: calc(100% - 200rpx);
		margin: 50rpx;

		.page-button {
			width: 90rpx;
			height: 90rpx;
			border-radius: 100%;
			background-color: #f3f4f6;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.voice-button {
			width: 110rpx;
			height: 110rpx;
			border-radius: 100%;
			background-image: linear-gradient(to bottom right, #7B4DFF, #FF4D8C);
			display: flex;
			justify-content: center;
			align-items: center;
			box-shadow: 0 3rpx 9rpx #ccc;
		}
	}

	.end-button {
		display: flex;
		align-items: center;
		justify-content: center;
		background-image: linear-gradient(to right, #7B4DFF, #FF4D8C);
		color: #fff;
		border-radius: 233rpx;
		padding: 30rpx 90rpx;
		margin-top: 50rpx;
		text-align: center;
		font-size: 32rpx;
		letter-spacing: 0.1em;
		box-shadow: 0 3rpx 9rpx #ccc;
		transition: all 0.8s ease-in-out;
	}
}
</style>
